<script src="/include/calendar/calendar.js"></script>
<style type="text/css">
a {
	cursor: pointer;
}
</style>
<div class="pageheader">
	<h2>
		<i class="fa fa-pencil-square"></i>日志管理
	</h2>
	<div class="breadcrumb-wrapper">
		<span class="label">你所在的位置：</span>
		<ol class="breadcrumb">
			<li><a href="/index">ERP管理系统</a></li>
			<li>日志管理</li>
			<li class="active">报货日志</li>
		</ol>
	</div>
</div>
<div class="contentpanel">
    <div class="main">
        <form id="search-form" class="form-inline" method="post" action="/log/baohuo" style="margin-bottom: 10px;">
            <div class="form-group">
                <label for="date">日期:</label>
                <input class="form-control" type="text" name="starttime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->starttime;?>">
	                       至<input class="form-control" type="text" name="endtime" onclick="new Calendar().show(this);" readonly="readonly" value="<?php echo $this->endtime;?>">
            </div>
            <button type="submit" class="btn btn-primary">搜索</button>
        </form>
        <form id="print-form" method="post" target="_blank" action="/stock/printbaohuo">
            <div class="table-responsive">
                <table class="table table-bordered table-hover">
                    <thead>
                        <tr>
                            <th width="100px;"><input type="checkbox" name="selectall">&nbsp;&nbsp;全选</th>
                            <th>SKU</th>
                            <th>产品名称</th>
                            <th width="200px;">尺码和数量</th>
                            <th>备注</th>
                            <th>日期</th>
                            <th>报货员</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>      
                        <?php 
                        if ($this->logList){
                            foreach ($this->logList as $v){
                        ?>
                        <tr>
				            <td><input type="checkbox" name="isprint[]" value="<?php echo $v['sku'];?>">打印</td>
                            <td><?php echo $v['sku'];?></td>
                            <td><?php echo $v['title'];?></td>
                            <td class="sizenum">
                                <?php  
                                $info = json_decode($v['info'], true);
                                foreach($info as $_v){
                        	        echo $_v[0] . '/' . stripslashes($_v[1]) . ';&nbsp;&nbsp;';
                        	        echo '<input class="form-control" type="hidden" data-name="sizenum['.$v['sku'].'][]['.$_v[0].']" value="'.stripslashes($_v[1]).'">';
                                }
                                ?>
				            </td>
				            <td class="memo"><?php echo $v['memo']; ?><input type="hidden" data-name="memo[<?php echo $v['sku']; ?>]" value="<?php echo $v['memo']; ?>"></td>
				            <td><?php echo $v['add_time']; ?></td>
				            <td><?php echo $v['add_user'];?></td>
				            <td><a href="javascript:void(0);" onclick="deleteBaohuo(<?php echo $v['id']; ?>, this)">删除</a></td>
			            </tr> 
			            <?php 
                            } 
                        }
                        ?>
			            <tr>
			                <td colspan="8">
			                    <?php echo $this->paginationControl ( $this->paginator, 'Sliding', 'page/pager.phtml', array (
			                    		'title' => $this->title,
			                    		'starttime' => $this->starttime,
			                    		'endtime' => $this->endtime 
			                    		) );?>
			                </td>
			            </tr>
		            </tbody>
                </table>
                <input class="confirm btn btn-primary" type="submit" value="批量打印">
                <input class="btn btn-primary excel" type="submit" name="excel" value="导出Excel表">
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$("input[name='isprint[]']").each(function(i){
	    $(this).click(function(){
		    if($(this).is(':checked')){
	            $("tbody tr:eq("+i+") .sizenum input").each(function(j){
		            $(this).attr("name",$(this).data("name"));
		        });
	            $("tbody tr:eq("+i+") .memo input").attr("name",$("tbody tr:eq("+i+") .memo input").data("name"));
	        }else{
	            $("tbody tr:eq("+i+") .memo input").removeAttr("name");
	            $("tbody tr:eq("+i+") .sizenum input").each(function(j){
		            $(this).removeAttr("name");
		        });
	        }
	    });
	});
	$("input[name='selectall']").click(function(){
		check = this.checked;		
		$('input[name="isprint[]"]').each(function(){
			this.checked = check;
		});			
		if($(this).is(':checked')){
			$("tbody .sizenum input").each(function(j){
	            $(this).attr("name",$(this).data("name"));
	        });
			$("tbody .memo input").each(function(){
	            $(this).attr("name",$(this).data("name"));
			});
		}else{
            $("tbody .sizenum input").each(function(j){
	            $(this).removeAttr("name");
	        });
			$("tbody .memo input").each(function(){
	            $(this).removeAttr("name");
			});
		}
	});
	$("input.excel").click(function(){
		$(this).val('excel');
	});
});
//删除日志
function deleteBaohuo(id, obj) {
    if (confirm('确认删除?')) {
        $.ajax({
            type: "get",
            url: "/log/deletebh?id="+id,
            data: {},    
            success: function(data) {
                switch(data) {	
                    case "1":$(obj).parent().parent().remove();break;
        			default:alert('删除失败');
        		}
        	}			
        });
    }
}
</script>